﻿using MaterialDesignThemes.Wpf.Transitions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SPW.Component
{
    public class TransitioningContentEx : TransitioningContentBaseEx
    {
        static TransitioningContentEx()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TransitioningContentEx), new FrameworkPropertyMetadata(typeof(TransitioningContentEx)));
        }

        public TransitioningContentEx()
        {
            Loaded += (sender, args) => Run(TransitioningContentRunHint.Loaded);
            IsVisibleChanged += (sender, args) => Run(TransitioningContentRunHint.IsVisibleChanged);
        }

        public static readonly DependencyProperty RunHintProperty = DependencyProperty.Register(
            nameof(RunHint), typeof(TransitioningContentRunHint), typeof(TransitioningContentEx), new PropertyMetadata(TransitioningContentRunHint.All));

        public TransitioningContentRunHint RunHint
        {
            get => (TransitioningContentRunHint)GetValue(RunHintProperty);
            set => SetValue(RunHintProperty, value);
        }

        private void Run(TransitioningContentRunHint requiredHint)
        {
            if ((RunHint & requiredHint) == requiredHint)
                RunOpeningEffects();
        }

        public void RunOfCallback(Action callback)
        {
            RunOpeningEffects(callback);
        }
    }
}
